@extends('backend.layouts.app')

@section('title', $title = $plat->id ? '编辑平台' : '添加平台' )

@section('breadcrumb')
    <a href="">系统设置</a>
    <a href="">平台管理</a>
    <a href="">{{$title}}</a>
@endsection

@section('content')
    <div class="layui-main">

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{ $title }}</legend>
        </fieldset>

        <form class="layui-form layui-form-pane" method="POST"
              action="{{ $plat->id ? route('main_game_plat.update', $plat->id) : route('main_game_plat.store') }}">
            {{ csrf_field() }}
            <input type="hidden" name="_method" class="mini-hidden" value="{{ $plat->id ? 'PATCH' : 'POST' }}">


            <div class="layui-form-item">
                <label class="layui-form-label">平台名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="main_game_plat_name" required lay-verify="required" placeholder="请输入平台名称<"
                           autocomplete="off" class="layui-input"
                           value="{{ old('main_game_plat_name',$plat->main_game_plat_name) }}"
                           @if($plat->id) disabled @endif>
                </div>
                <div class="layui-form-mid layui-word-aux">请填写2到32位网站名，必须完全是字母、数字</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">平台编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="main_game_plat_code" required lay-verify="required" placeholder="请输入平台编号"
                           autocomplete="off" class="layui-input"
                           value="{{ old('main_game_plat_code',$plat->main_game_plat_code) }}"
                           @if($plat->id) disabled @endif>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">比率</label>
                <div class="layui-input-inline">
                    <input type="text" name="rate" required lay-verify="required" placeholder="请输入比率"
                           autocomplete="off" class="layui-input"
                           value="{{ old('rate',$plat->rate) }}">
                </div>
                <div class="layui-form-mid layui-word-aux">不超过1的小数，最多保留4位小数</div>
            </div>
            @if($plat->id)
                <div class="layui-form-item">
                    <label class="layui-form-label">线路</label>
                    @foreach($plat->line() as $line)
                        <div class="layui-inline">
                            <label class="layui-form-label">{{$line['lineName']}}:</label>
                            @if($line['default'])
                                <div class="layui-form-mid layui-word-aux">默认</div>
                            @endif
                        </div>


                    @endforeach
                </div>
            @endif
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="是" @if($plat->status) checked @endif>
                    <input type="radio" name="status" value="0" title="否" @if(!$plat->status) checked @endif>
                </div>
            </div>


            <div class="layui-form-item">
                {{--<div class="layui-input-block">--}}
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                {{--</div>--}}
            </div>
        </form>
    </div>
@endsection

@section('scripts')
    <script>
        layui.use('form', function () {
            var form = layui.form;

            form.on('checkbox(plats_id)', function (data) {
                if (data.elem.checked) {
                    document.getElementById(data.elem.getAttribute('data-id')).disabled = false;
                    document.getElementById(data.elem.getAttribute('data-id')).setAttribute('lay-verify', 'rate');
                } else {
                    document.getElementById(data.elem.getAttribute('data-id')).disabled = true;
                    document.getElementById(data.elem.getAttribute('data-id')).setAttribute('lay-verify', '');
                }

            });

            form.verify({
                rate: [
                    /^0\.\d{1,4}/
                    , '比率必须大于等于0保留四位小数，并且小于1，'
                ]
            });
        });

    </script>
@endsection